#ifdef GL_ES
//precision mediump float;
precision lowp float;
precision lowp sampler2D;
#endif

uniform sampler2D sampler2d;
varying vec2 vtex;
uniform float angle;
uniform float dic; //1 顺时针 -1逆时针

void main(void)
{       
	//可以实现360°切割 可通过旋转坐标系控制初始角度
	vec2 uv = vtex - vec2(0.5, 0.5);
	//gl_FragColor = texture2D(sampler2d, vtex) * smoothstep(0.0, 1.0, angle-degrees(a));
	//gl_FragColor = texture2D(sampler2d, vtex) * alpha;
	
	if(dic < 0.) {	
		uv.y = -uv.y;// 逆时针旋转
	}
	float tanA = abs(uv.y/uv.x);
	
	if(uv.y > 0. && uv.x >= 0.) {
	//第1象限
		if(angle >= 90.){
			gl_FragColor = texture2D(sampler2d, vtex) * 1.;
		}else if(angle >= 0. && angle <= 90.) {
			if(tan(radians(angle)) > tanA) {
				gl_FragColor = texture2D(sampler2d, vtex) * 1.;
			}else {
				gl_FragColor = texture2D(sampler2d, vtex) * 0.;
			}
		}else{
			gl_FragColor = texture2D(sampler2d, vtex) * 0.;
		}
	}else if(uv.y >= 0. && uv.x < 0.) {
	//第2象限
		if(angle > 180.){
			gl_FragColor = texture2D(sampler2d, vtex) * 1.;
		}else if(angle <= 90.) {
			gl_FragColor = texture2D(sampler2d, vtex) * 0.;
		}else {
			if(tan(radians(180.-angle)) < tanA) {
				gl_FragColor = texture2D(sampler2d, vtex) * 1.;
			}else {
				gl_FragColor = texture2D(sampler2d, vtex) * 0.;
			}
		}
	}else if(uv.y < 0. && uv.x <= 0.) {
	//第3象限
		if(angle > 270.){
			gl_FragColor = texture2D(sampler2d, vtex) * 1.;
		}else if(angle <= 180.) {
			gl_FragColor = texture2D(sampler2d, vtex) * 0.;
		}else {
			if(tan(radians(angle-180.)) > tanA) {
				gl_FragColor = texture2D(sampler2d, vtex) * 1.;
			}else {
				gl_FragColor = texture2D(sampler2d, vtex) * 0.;
			}
		}
	}else if(uv.y <= 0. && uv.x > 0.) {
	//第4象限
		if(angle > 360.){
			gl_FragColor = texture2D(sampler2d, vtex) * 1.;
		}else if(angle <= 270.) {
			gl_FragColor = texture2D(sampler2d, vtex) * 0.;
		}else {
			if(tan(radians(360.-angle)) < tanA) {
				gl_FragColor = texture2D(sampler2d, vtex) * 1.;
			}else {
				gl_FragColor = texture2D(sampler2d, vtex) * 0.;
			}			
		}
	}
	return;
}